/**
 * 
 */
package fr.isima.isipaint.model;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Ellipse2D;

/**
 * @author daniel
 * 
 */
public final class Oval extends GraphicObject {

	/**
	 * Default constructor
	 */
	public Oval() {
		super();
	}

	/**
	 * 
	 * @param x
	 *            The x coordinate of the oval
	 * @param y
	 *            The y coordinate of the oval
	 * @param width
	 *            The width of the oval
	 * @param height
	 *            The height of the oval
	 */
	public Oval(int x, int y, int width, int height) {
		super(x, y, width, height);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		super.paintComponent(g2);
		//System.out.println("Draw an Oval" + this);
		g2.setColor(color);

		if (filled) {
			g2.fillOval(getParent().getX(), getParent().getY(),
					(int) (getWidth() - stroke.getLineWidth()),
					(int) (getHeight() - stroke.getLineWidth()));
		} else {
			g2.drawOval(getParent().getX(), getParent().getY(),
					(int) (getWidth() - stroke.getLineWidth()),
					(int) (getHeight() - stroke.getLineWidth()));
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.JComponent#contains(int, int)
	 */
	@Override
	public boolean contains(int x, int y) {
		int radiusWidth = getWidth() / 2;
		int radiusHeight = getHeight() / 2;
					
		boolean res = false;
		
		if(radiusWidth != 0 && radiusHeight != 0)
		{
			res = Math.pow((x/radiusWidth), 2.0) + Math.pow((y/radiusHeight),2.0) <= 1;
		}
		
		return res;
		
		
	}
}
